import vuetify, { transformAssetUrls } from "vite-plugin-vuetify";
// https://nuxt.com/docs/api/configuration/nuxt-config
// import { list } from './fonts'
// const families = list.reduce((l: {
//   [key: string]: any
// }, x) => {
//   l[x] = [400, 700]
//   return l
// }, {})
export default defineNuxtConfig({
  // 由于 "target" 不在类型 "InputConfig<NuxtConfig, ConfigLayerMeta>" 中，
  // 从 Nuxt 3 开始，target 配置可能已被弃用，可考虑使用 ssr 配置替代
  // 原代码已确保开启 SSR，这里移除 target 配置
  compatibilityDate: '2024-11-01',
  app: {
    head: {
      title: '这是一个项目名称',
      meta: [
        { name: 'description', content: 'My amazing Nuxt 3 app' },
        { name: 'keywords', content: 'nuxt,vue,seo' },
        { property: 'og:title', content: 'My Nuxt 3 App' },
        { property: 'og:description', content: 'My amazing Nuxt 3 app' },
      ],
      link: [
        { rel: 'canonical', href: 'https://example.com/page' },
      ],
      script: [
        { src: '/iconfonts.js' },
      ],
    },
  },
  runtimeConfig: {
    public: {
      apiBase: process.env.NUXT_PUBLIC_API_BASE,
    },
  },
  ssr: true, // 确保开启 SSR
  devtools: { enabled: true },
  build: {
    transpile: ["vuetify"],
  },
  modules: [
    (_options, nuxt) => {
      nuxt.hooks.hook("vite:extendConfig", (config) => {
        config!.plugins!.push(vuetify({ autoImport: true } as any) as any);
      });
    },
    '@nuxtjs/google-fonts',
    '@unocss/nuxt',
    '@element-plus/nuxt'
  ],
  css: [
    '@/reset.css',
    '@/iconFont.css',
  ],
  nitro: {
    // 添加代理配置
  },
  googleFonts: {
    families: {
      'Merriweather': [400, 700],
    }, // 使用通配符引入所有字体
    display: 'swap',
    preload: true,
  },
  unocss: {
    // 预设
    // uno: true,            // 启用@unocss/preset-uno
    attributify: true,    // 启用@unocss/preset-attributify
    icons: {              // 启用@unocss/preset-icons
      extraProperties: {
        display: "inline-block",
      },
      customizations: {
        iconCustomizer(collection, icon, props) {
          // 默认图标大小
          props.width = "1.5em";
          props.height = "1.5em";
        },
      },
    },
    // 核心选项
    shortcuts: [],
    rules: [],
  },
  vite: {
    vue: {
      template: {
        transformAssetUrls,
      },
    },
    server: {
      allowedHosts: ['api.ljjcloud.com'],
      proxy: {
        '/api': {
          target: 'https://www.nicepatches.com', // 目标API服务器
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''), // 可选：重写路径
        }
      }
    }
  },
})
